using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using XDQ.VAT.Classes;
using XDQ.VAT.Exams;
using XDQ.VAT.Exams.Dtos;
using XDQ.VAT.Web.Pages.Exams.AppExam.ViewModels;

namespace XDQ.VAT.Web.Pages.Exams.AppExam
{
    public class CreateModalModel : VATPageModel
    {
        [BindProperty]
        public CreateEditAppExamViewModel ViewModel { get; set; }

        private readonly IAppExamAppService _service;

        public CreateModalModel(IAppExamAppService service)
        {
            _service = service;
        }

        public virtual async Task OnGetAsync()
        {
            ViewModel = new CreateEditAppExamViewModel();
            ViewModel.Classes = this.ObjectMapper.Map(await _service.GetClassesAsync());
            ViewModel.Courses = this.ObjectMapper.Map(await _service.GetCoursesAsync());
        }

        public virtual async Task<IActionResult> OnPostAsync()
        {
            var dto = ObjectMapper.Map<CreateEditAppExamViewModel, CreateUpdateAppExamDto>(ViewModel);
            await _service.CreateAsync(dto);
            return NoContent();
        }
    }
}